package com.lanjie;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

public class LoginFilter implements Filter {

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("初始化");
        String age = filterConfig.getInitParameter("age");
        System.out.println(age);
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        System.out.println("执行filter");
        filterChain.doFilter(servletRequest,servletResponse); //接着往下走
        HttpServletRequest request = (HttpServletRequest) servletRequest;
        /*Object o = request.getSession().getAttribute("dangqianyonghu");
        if (o!=null){ //说明登录过了
            filterChain.doFilter(servletRequest,servletResponse);
        }else {
            request.getRequestDispatcher("/login.jsp").forward(request,servletResponse);
        }*/
    }

    @Override
    public void destroy() {
        System.out.println("销毁");
    }
}
